package TestFunc;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws IOException{
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要说的话：");
        String message = sc.nextLine();
        //敏感词屏蔽功能
        //列出敏感词
        message = harmonyTalk(message);
        System.out.println(message);
    }

    private static String harmonyTalk(String message) throws IOException {
        ArrayList<String> list = new ArrayList<>();
        BufferedReader wbr = new BufferedReader(new InputStreamReader
                (new FileInputStream("src/FollowTest/words.data")));
        String str = wbr.readLine();
        wbr.close();
        for (String s : str.split("&")) {
            list.add(s);
        }
        //替换
        for (String s : list) {
            if(message.contains(s))
            {
                int len = s.length();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < len; i++) {
                    sb.append("*");
                }
                String replacement = sb.toString();
                message = message.replace(s,replacement);
            }
        }
        return message;
    }
}
